package edu.whu.demo.service.impl;

import edu.whu.demo.domain.Supplier;
import edu.whu.demo.dao.SupplierDao;
import edu.whu.demo.service.ISupplierService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author zxj
 * @since 2023-10-18
 */
@Service
public class SupplierServiceImpl extends ServiceImpl<SupplierDao, Supplier> implements ISupplierService {
    @Autowired
    SupplierDao supplierDao;

    @Cacheable(cacheNames = "supplier",key = "#supplier",condition = "#supplier!=null")
    public Supplier addSupplier(Supplier supplier){
        supplierDao.insert(supplier);
        return supplier;
    }

    @CacheEvict(cacheNames = "supplier",key = "#supplier")
    public void delSupplierById(int id){
        supplierDao.deleteById(id);
    }

    public Supplier findSupplierById(int id){
        return supplierDao.selectById(id);
    }

    public void updateSupplierById(Supplier supplier){
        supplierDao.updateById(supplier);
    }
}
